package org.cuijq.thinking.in.spring.dependency.injection;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author by CuiJQ
 * @Classname XmlDepencySetterInjectionDemo
 * @Description XmlDepencySetterInjectionDemo Description
 * @Date 2021/6/29 9:04
 */
public class AwareInterfaceDepencyInjectionDemo implements BeanFactoryAware , ApplicationContextAware {

  private static BeanFactory beanFactory;
  private static ApplicationContext applicationContext;
  public static void main(String[] args) {
    //创建BeanFactory 容器
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    //注册
    context.register(AwareInterfaceDepencyInjectionDemo.class);

    context.refresh();

    System.out.println(beanFactory == context.getBeanFactory());
    System.out.println(applicationContext == context);

    context.close();
  }

  @Override
  public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    AwareInterfaceDepencyInjectionDemo.beanFactory =beanFactory;
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    AwareInterfaceDepencyInjectionDemo.applicationContext =applicationContext;
  }
}
